//package com.example.lockdemo.handle;
//
//import cn.hutool.extra.spring.SpringUtil;
//import com.example.lockdemo.config.MyFunc;
//import com.example.lockdemo.config.MyParam;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.context.expression.BeanFactoryResolver;
//import org.springframework.core.DefaultParameterNameDiscoverer;
//import org.springframework.core.ParameterNameDiscoverer;
//import org.springframework.expression.BeanResolver;
//import org.springframework.expression.Expression;
//import org.springframework.expression.ExpressionParser;
//import org.springframework.expression.ParserContext;
//import org.springframework.expression.common.TemplateParserContext;
//import org.springframework.expression.spel.standard.SpelExpressionParser;
//import org.springframework.expression.spel.support.StandardEvaluationContext;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Parameter;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author GuoAo
// * @className MyParamHandle
// * @date 2025/4/27
// * @description TODO
// */
//@Aspect
//@Slf4j
//@Component
//public class MyParamHandle {
//
//    @Before(value = "@annotation(func)")
//    public void before(JoinPoint joinPoint, MyFunc func){
//        ExpressionParser parser = new SpelExpressionParser();
//        ParserContext parserContext = new TemplateParserContext();
//        ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer();
//        // Spring的Bean对象解析器  SpringUtil需要引入hutool依赖
//        BeanResolver resolver = new BeanFactoryResolver(SpringUtil.getBeanFactory());
//        StandardEvaluationContext context = new StandardEvaluationContext();
//        // 赋予上下文解析器解析Bean对象的能力
//        context.setBeanResolver(resolver);
//        Object[] args = joinPoint.getArgs();
//        MethodSignature signature =(MethodSignature) joinPoint.getSignature();
//        String[] parameterNames = pnd.getParameterNames(signature.getMethod());
//        Parameter[] parameters = signature.getMethod().getParameters();
//        List<MyParam> paramList = new ArrayList<>();
//        for (int i = 0; i < args.length; i++){
//            assert parameterNames != null;
//            log.info("agrName: {},agr: {}", parameterNames[i], args[i]);
//            context.setVariable(parameterNames[i], args[i]);
//
//            if(parameters[i].isAnnotationPresent(MyParam.class)){
//                paramList.add(parameters[i].getAnnotation(MyParam.class));
//            }
//
//        }
//        paramList.forEach(param -> {
//            Expression expression = null;
//            String expr = param.expr();
//            // * 如果是#{} 表示时计算表达式 也可以是其他方法的调用 getExpressionPrefix()-> #{   getExpressionSuffix()-> }
//            if(expr.startsWith(parserContext.getExpressionPrefix()) && expr.endsWith(parserContext.getExpressionSuffix())){
//                expression = parser.parseExpression(expr, parserContext);
//            }else{
//                // * # 开头的是直接解析属性
//                expression = parser.parseExpression(expr);
//            }
//            Class<?> type = param.type();
//            Object value = expression.getValue(context, type);
//            log.info("value:{}",value);
//        });
//
//    }
//}
